package month3.day30;

public class Zulingonsi {
    private String name;
    private String dianhua;
    Car[] car = new Car[100];
    Zulingxinxi[]zulingxinxis=new Zulingxinxi[1000];
    int count = 0;
    private double jiner;
    int zulingshu=0;

    public Zulingonsi(String name, String dianhua) {
        this.name = name;
        this.dianhua = dianhua;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDianhua() {
        return dianhua;
    }

    public void setDianhua(String dianhua) {
        this.dianhua = dianhua;
    }

    //判断是否重复车牌
    public boolean panduan(String chepai) {
        for (int i = 0; i < count; i++) {
            if (car[i].getChepai().equals(chepai)) {
                return false;
            }
        }
        return true;
    }

    public void xinche(String chepai, String pingpai, double money, int zuowei) {
        car[count] = new Keche(chepai, pingpai, money, zuowei);
        count++;
        System.out.println("采购成功");
    }

    public void xinche(String chepai, String pingpai, double money, String xinghao) {
        car[count] = new Jiaoche(chepai, pingpai, money, xinghao);
        count++;
        System.out.println("采购成功");
    }

    public void baofei(String num) {
        for (int i = 0; i < count; i++) {
            if (car[i].getChepai().equals(num)) {
                System.out.println("已报废");
                int j=0;
                for(j=i;j<count-1;j++){
                    car[j] = car[j + 1];
                }
                car[j]=null;
                count--;
                return;
            }
        }
    }

    public double zuche(int day,String name,String num) {
        for (int i = 0; i < count; i++) {
            if (car[i].getChepai().equals(num) && car[i].getZuangtai().equals("当前可租")) {
                car[i].setZuangtai("已租出");
                jiner=car[i].zujin(day);
                zulingxinxis[zulingshu]=new Zulingxinxi(name,num);
                zulingshu++;
                return jiner;
            }
        }
        return 0;
    }

    public String zujin(int day,String name,String num) {
        if (zuche(day,name,num) == 0)
            return "租车失败";
        return "租车成功，租金：" +jiner;

    }

    public void yichuzu() {
        for (int i = 0; i < count; i++) {
            if (car[i].getZuangtai().equals("已租出")) {
                if (car[i] instanceof Keche)
                    ((Keche) car[i]).show();
                if (car[i] instanceof Jiaoche)
                    ((Jiaoche) car[i]).show();
            }
        }
    }

    public void huanche(String num) {
        for (int i = 0; i < count; i++) {
            if (car[i].getZuangtai().equals("已租出") && car[i].getChepai().equals(num)) {
                car[i].setZuangtai("当前可租");
                System.out.println("归还成功");
                return;
            }
        }
        System.out.println("未找到该出租车辆");
    }

    public void show() {
        for (int i = 0; i < count; i++) {
            if (car[i] instanceof Keche)
                ((Keche) car[i]).show();        }
    }

    public void show(int number) {
        for (int i = 0; i < count; i++) {
            if (car[i] instanceof Jiaoche)
                ((Jiaoche) car[i]).show();
        }
    }
    public void xinxi(){
        for(int i=0;i<zulingshu;i++){
            System.out.println("租赁人："+zulingxinxis[i].getName()+",租赁车牌："+zulingxinxis[i].getChepai());
        }
    }


}
